package com.gigi.datageniebackendmaster.controller;

import com.gigi.datageniebackendmaster.common.BaseResponse;
import com.gigi.datageniebackendmaster.model.entity.UserEntity;
import com.gigi.datageniebackendmaster.model.request.LoginRequest;
import com.gigi.datageniebackendmaster.model.request.RegisterRequest;
import com.gigi.datageniebackendmaster.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Api(tags = "用户管理")
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "注册")
    @PostMapping("register")
    public BaseResponse<Boolean> register(@RequestBody @Valid RegisterRequest request) {
        return userService.register(request);
    }

    @ApiOperation(value = "登录")
    @PostMapping("login")
    public BaseResponse<Boolean> login(@RequestBody @Valid LoginRequest request, HttpServletRequest httpServletRequest) {
        return userService.login(request, httpServletRequest);
    }

    @ApiOperation(value = "获取当前用户")
    @GetMapping("currentUser")
    public BaseResponse<UserEntity> currentUser(HttpServletRequest httpServletRequest) {
        return userService.currentUser(httpServletRequest);
    }

    @ApiOperation(value = "注销")
    @PostMapping("outLogin")
    public BaseResponse<Boolean> outLogin(HttpServletRequest httpServletRequest) {
        return userService.outLogin(httpServletRequest);
    }

}
